package org.baicaixiaozhan.learn.guava.base;

import com.google.common.base.Stopwatch;
import java.util.concurrent.TimeUnit;

/**
 * DESC: {@link Stopwatch} 时间操作示例
 *
 * @author : baicaixiaozhan
 * @since : 2020-11-11
 */
public class StopWatchDemo {

    public static void main(String[] args) throws InterruptedException {

        Stopwatch stopwatch = Stopwatch.createUnstarted();

        // start() -> stop() 表示 记录这一段时间总和
        // 区分 System.nanoTime() / System.currentTimeMillis()
        Stopwatch start = stopwatch.start();
        System.out.println(start.elapsed(TimeUnit.SECONDS));

        Thread.sleep(5 * 1000);

        Stopwatch stop = stopwatch.stop();
        System.out.println(stop.elapsed(TimeUnit.SECONDS));
    }


}
